import {defineConfig, loadEnv, ConfigEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'
import {resolve} from "path";

const pathResolve = (dir: string) => {
    return resolve(__dirname, '.', dir);
};
// https://vite.dev/config/
const viteConfig = defineConfig((mode: ConfigEnv) => {
    const env = loadEnv(mode.mode, process.cwd());
    return {
        plugins: [
            vue(),
            vueJsx(),
            vueDevTools(),
        ],
        resolve: {
            alias: {
                '/@': pathResolve('./src/'),
            },
        },
        root: process.cwd(),
        server: {
            host: '0.0.0.0',
            port: env.VITE_PORT as unknown as number,
            open: JSON.parse(env.VITE_OPEN),
            hmr: true,
            proxy: {
                '/e9bi486350980u340r98u234098u3': {
                    target: env.VITE_API_URL,
                    // target: 'https://im.wocoding.cn/5e084fda0',
                    ws: true,
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/e9bi486350980u340r98u234098u3/, ''),
                }
            },
        },
    }
})

export default viteConfig;
